<template>
    <div>
      <h3>{{ user.name }}</h3>
      <p>{{ user.age }} 岁</p>
    </div>
  </template>
  
  <script setup>
  import axios from 'axios';
  import { ref, onMounted } from 'vue';
  
  const user = ref({});
  
  onMounted(async () => {
    try {
      const response = await axios.get('/api/user');
      user.value = response.data;
    } catch (error) {
      console.error('Error fetching user data:', error);
    }
  });
  </script>